package com.thread;

public class ThreakHomework02 {
    public static void main(String[] args) {
        Tum tum = new Tum();
        Thread m1 = new Thread(tum);
        m1.setName("m1");
        Thread m2 = new Thread(tum);
        m2.setName("m2");
        m2.start();
        m1.start();
    }
}
class Tum implements Runnable{
    private int money = 1000;
    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                if (money < 1000) {
                    System.out.println("余额不足");
                    return;
                }
                money -= 1000;
                System.out.println(Thread.currentThread().getName()+"取出1000");
            }
            try{
                Thread.sleep(100);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }
}

